#ifndef PRINTERMANAGER_H
#define PRINTERMANAGER_H

#include <QPrinter>
#include <QPrinterInfo>
#include <QDebug>
#include <QTextDocument>
#include <QPainter>
#include <QDateTime>
#include <QQuickImageProvider>
#include <QQmlApplicationEngine>
#include <cmath>
#include "reportManager.h"


class PrintPreviewProvider: public QObject, public QQuickImageProvider
{
    Q_OBJECT
public:
    PrintPreviewProvider();
    QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
    QImage* pm;
};



extern QMap<int, QVariantMap> expLogInfo;

class PrinterManager : public QObject
{
    Q_OBJECT

private:
    PrinterManager();



public:
    static PrinterManager& I();

    void initProvider(QQmlApplicationEngine* engine);

    Q_INVOKABLE QStringList getPrinterList();
    Q_INVOKABLE void print(QString printerName);
    Q_INVOKABLE void refreshPreview(double dp);

    QPainter* generatePainter();     // 基于QPainter绘制打印内容
    void painterDrawExpInfo(QPainter* painter);
    void painterDrawExpLog(QPainter* painter);


    QString generateHTML();

private:

    int BH = 935;
    int BW = 720;

    QFont font1;
    QFont font2;


    double dp = 1;

    PrintPreviewProvider* provider;
    QImage* image;

    QMap<QString, QString> expInfo;

};

#endif // PRINTERMANAGER_H
